package com.aaa.goodsservice;

import com.aaa.goodsservice.config.MyRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: YuXin
 * @Date : Created in 2020/11/3 16:58
 * @ClassName : GoodsApplication
 * @Description :
 * @Package_Name : com.aaa.goodsservice
 */
@SpringBootApplication
@MapperScan("com.aaa.goodsservice.mapper")
//@EnableEurekaClient //开启Eureka客户端 该注解只对注册中心是Eureka有效
@EnableDiscoveryClient  //开启发现客户端  该注解对任意注册中心有效
@EnableTransactionManagement  //开启事务管理
@RibbonClient(name = "goodsClient", configuration = MyRule.class)
public class GoodsApplication {
    public static void main(String[] args) {
        SpringApplication.run(GoodsApplication.class, args);
    }

    /**
     * 初始化RestTemplate对象
     */
    @Bean
    @LoadBalanced  //调用远程接口时候   使用配置的负载均衡规则
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}